<template>
  <div>
    <Header></Header>

    <div class="my-container">
      <h2>{{ blog.title }}</h2>
      <el-link icon="el-icon-edit" v-if="ownBlog">
        <router-link :to="{name: 'BlogEdit', params: {blogId:blog.id}}">
          编辑
        </router-link>
      </el-link>

      <el-divider></el-divider>
      <div v-html="blog.content" class="markdown-body"></div>
    </div>
  </div>
</template>

<script>
import Header from "../components/Header.vue"
import 'github-markdown-css'

export default {
  name: "BlogDetail",
  components: {Header},
  data() {
    return {
      blog: {
        title: '标题',
        content: '内容',
      },
      ownBlog: false
    }
  },
  created() {
    const blogId = this.$route.params.blogId
    const _this = this

    this.$axios.get('/blogs/blog/' + blogId).then(res => {
      const blog = res.data.data

      _this.blog.id = blog.id
      _this.blog.title = blog.title

      let MardownIt = require('markdown-it')
      let md = new MardownIt()

      _this.blog.content = md.render(blog.content)

      this.ownBlog = (blog.userId === _this.$store.getters.GET_INFO.id)
    })
  }
}
</script>

<style scoped>
.my-container {
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  width: 100%;
  min-height: 700px;
  padding: 20px 15px;
}
</style>